import http from '../../utils/http'
Page({

  
  data: {
    page:1,list:[],start:'',end:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
 
  },
  getlist(){
    let uid=  wx.getStorageSync('uid')
     if(uid){
     http('/index/record','post',{ uid,limit:10,page:this.data.page,start_time:this.data.start,end_time:this.data.end }).then(res=>{
               console.log(res);
               if(this.data.page==1){
                 this.setData({
                   list:res.data.data,
                   count:res.data.count
                 })
               }else{
                 let list=this.data.list
               let list1= list.concat(res.data.data)
                 this.setData({
                   list:list1
                 })
               }
     })
  }
  },
  remove(e){

   wx.showModal({
     title:'确定删除吗',
     cancelColor: 'cancelColor',
     success:(res)=>{
       console.log(res);
       if(res.confirm){
        let uid=wx.getStorageSync('uid')
        let id=e.currentTarget.dataset.id
        http('/index/record_del','post',{ uid,id}).then(res=>{
          console.log(res);
          wx.showToast({
            title: '删除成功',
          })
          this.getlist()
        }).catch(res=>{
          wx.showToast({
            title: '删除失败',
          })
        })
       }
     }
    
   })

   
    
   
  },
  toDetail(e){
    console.log(e);
    let item=JSON.stringify(e.currentTarget.dataset.item)
    wx.navigateTo({
      url: '/pages/detail/detail?item='+item,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getlist()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log(11);
    let list=this.data.list
    let count=this.data.count
    let page=this.data.page
      if(list.length<count){
        this.setData({
          page:page+1
        })
        this.getlist()
      }
  },
  change(e){
    console.log(e);
    this.setData({
      start:e.detail.value
    })
    this.getlist()
  },
  change1(e){
    this.setData({
      end:e.detail.value
    })
    this.getlist()
    
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },

  /**
   * 跳转单页
   */
  infoClick:function(){
    wx.navigateTo({
      url: '../jiaocheng/jiaocheng?id=2'
    })
  },

})